package demo1;

import java.util.Arrays;

public class MyStack {
    int[] array;
    int size;

    public MyStack() {
        array = new int[5];
    }
    public int push(int val){
        if(size== array.length){
            array= Arrays.copyOf(array,2*array.length);
        }
        array[size]=val;
        size++;
        return val;
    }
    public int pop(){
        if(empty()){
            throw new EmptyException();
        }else{
            int val = array[size-1];
            size--;
            return val;
        }
    }
    public int peek(){
        if(empty()){
            throw new EmptyException();
        }else{
            return array[size-1];
        }
    }
    public int size(){
        return size;
    }
    public boolean empty(){
        return size==0;
    }
}
